import { defineStore } from 'pinia'
import { getPagePath } from '@/libs/utils/sys'
export const useAppStore = defineStore('app', {
  state: () => ({
    redirectLoginUrl: '',
    tabList: [
      {
        id: 3,
        tab_key: 'right',
        text: '个人中心',
        text_select_color: '#48a6a9',
        icon_url:
          'https://dtest.psychcn.com/positive_friendsDiary/Icon／Profile@2x202350918134774.png',
        select_icon_url:
          'https://dtest.psychcn.com/positive_friendsDiary/Icon／Profile@2x (1)202350918135270.png',
        path_url: '/pages/index/index'
      },
      {
        id: 2,
        tab_key: 'center',
        text: '首页',
        text_select_color: '#48a6a9',
        icon_url:
          'https://dtest.psychcn.com/positive_friendsDiary/Icon／Profile@2x202350918134774.png',
        select_icon_url:
          'https://dtest.psychcn.com/positive_friendsDiary/Icon／Profile@2x (1)202350918135270.png',
        path_url: '/pages/index1/index1'
      },
      {
        id: 1,
        tab_key: 'left',
        text: '我的计划',
        text_select_color: '#48a6a9',
        icon_url:
          'https://dtest.psychcn.com/positive_friendsDiary/Icon／plan@2x202350918123769.png',
        select_icon_url:
          'https://dtest.psychcn.com/positive_friendsDiary/Icon／plan@2x (1)202350918124144.png',
        path_url: '/pages/index2/index2'
      }
    ],
    tabCurrent: 0
  }),

  actions: {
    setRedirectLoginUrl(e) {
      this.redirectLoginUrl = e
    },
    setTabCurrent(e = -1) {
      if (e < 0) {
        const pagesPath = getPagePath()
        const index = this.tabList.findIndex((v) => v.path_url === pagesPath)
        this.tabCurrent = index === -1 ? 0 : index
      } else {
        this.tabCurrent = e
      }
    }
  }
})
